#coding=utf-8
import base64


def pic2py(picture_names, py_name):

    write_data = []
    for picture_name in picture_names:
        filename = picture_name.replace('.', '_')
        open_pic = open("%s" % picture_name, 'rb')
        b64str = base64.b64encode(open_pic.read())
        open_pic.close()
        write_data.append('%s = "%s"\n' % (filename, b64str.decode()))

    f = open('%s.py' % py_name, 'w+')
    for data in write_data:
        f.write(data)
    f.close()


if __name__ == '__main__':
    pics = ["again.png", "background.png", "bomb.png", "bomb_supply.png",\
            "bullet_supply.png", "bullet1.png", "bullet2.png", "bullet3.png", "enemy1.png",\
            "enemy1_down1.png", "enemy1_down2.png", "enemy1_down3.png",\
            "enemy1_down4.png", "enemy2.png", "enemy2_down1.png", "enemy2_down2.png",\
            "enemy2_down3.png", "enemy2_down4.png", "enemy2_hit.png", "enemy3_n1.png",\
            "enemy3_n2.png", "enemy3_down1.png", "enemy3_down2.png", "enemy3_down3.png",\
            "enemy3_down4.png", "enemy3_down5.png", "enemy3_down6.png", "enemy3_hit.png",\
            "gameover.png", "life.png", "life_new.png" ,"me_destroy_1.png", "me_destroy_2.png",\
            "me_destroy_3.png", "me_destroy_4.png", "me1.png", "me2.png", "pause_nor.png",\
            "pause_pressed.png", "resume_nor.png", "resume_pressed.png", "font.ttf",\
            "record1.txt", "record2.txt", "bullet.wav", "enemy1_down.wav", "enemy2_down.wav",\
            "enemy3_down.wav", "enemy3_flying.wav", "get_bomb.wav", "get_bullet.wav",\
            "me_down.wav", "supply.wav", "upgrade.wav", "use_bomb.wav", "game_music.ogg"]
    pic2py(pics, 'memory_pic')
    print("ok")
